#!/bin/bash
#获取本地路径
DIR=$(cd $(dirname $0) && pwd )
LOGDIR="/logs"

case "$1" in
start)
#echo $DIR
#删除存在的pid文件
rm -rf $DIR'/vendor/workerman/_*'
rm -rf $DIR'/service/vendor/workerman/_*'

#判断文件夹是否存在
if [ ! -d "."$LOGDIR ];then
mkdir "."$LOGDIR
fi
#开启进程
#文件预处理服务
nohup /usr/bin/php $DIR'/public/server.php' start > $DIR$LOGDIR'/server.log' 2>&1 &
#合并文件服务
nohup /usr/bin/php $DIR'/public/merge.php' start > $DIR$LOGDIR'/merge.log' 2>&1 &
#redis发布订阅服务
nohup /usr/bin/php $DIR'/public/subscribe.php' start > $DIR$LOGDIR'/subscribe.log' 2>&1 &
#盒子客户端中控进程
nohup /usr/bin/php $DIR'/public/websocket.php' start > $DIR$LOGDIR'/websocket.log' 2>&1 &
#待删除
#nohup /usr/bin/php $DIR'/service/UploadedFileMiddle.php' start > $DIR$LOGDIR'/UploadedFileMiddle.log' 2>&1 &

sleep 1

if [ -n "`ps aux | grep "server.php" | grep -v grep `" ] 
then
echo -e "start server.php ---------------ok";
else
echo -e "start server.php ---------------fail";
fi

if [ -n "`ps aux | grep "merge.php" | grep -v grep `" ] 
then
echo "start merge.php ---------------ok";
else
echo "start merge.php ---------------fail";
fi

if [ -n "`ps aux | grep "subscribe.php" | grep -v grep `" ] 
then
echo "start subscribe.php ---------------ok";
else
echo "start subscribe.php ---------------fail";
fi

if [ -n "`ps aux | grep "websocket.php" | grep -v grep `" ] 
then
echo "start websocket.php ---------------ok"; 
else
echo "start websocket.php ---------------fail";
fi


exit 0;
;;

stop)
#判断文件夹是否存在
if [ ! -d "."$LOGDIR ];then
mkdir "."$LOGDIR
fi

#关闭服务
/usr/bin/php $DIR'/public/server.php' stop > $DIR$LOGDIR'/server.log' 2>&1 &
/usr/bin/php $DIR'/public/merge.php' stop > $DIR$LOGDIR'/merge.log' 2>&1 &
/usr/bin/php $DIR'/public/subscribe.php' stop > $DIR$LOGDIR'/subscribe.log' 2>&1 &
/usr/bin/php $DIR'/public/websocket.php' stop > $DIR$LOGDIR'/websocket.log' 2>&1 &

/usr/bin/php $DIR'/service/UploadedFileMiddle.php' stop > $DIR$LOGDIR'/upload.log' 2>&1 &

;;

esac
exit 0


